from src.data import DataSeq
import time

# 冒泡排序 我最喜欢的实验品
def BubbleSort(ds,v):
    assert isinstance(ds, DataSeq), "Type Error"

    Length = ds.length
    for i in range(Length - 1, -1, -1):
        for j in range(0, i, 1):
            if ds.data[j] > ds.data[j + 1]:
                ds.Swap(j, j + 1)
            time.sleep(v)


def create_bubblesort(title,v,l):
    ds = DataSeq(l, sort_title=title)
    ds.Visualize()
    ds.StartTimer()
    BubbleSort(ds,v)
    ds.StopTimer()
    ds.SetTimeInterval(0)
    time.sleep(3)
    ds.destory()
    return 0
    # ds.Visualize()


if __name__ == "__main__":
    create_bubblesort("bubblesort", float(0.5),int(10))


